
import 'package:shelf_router/shelf_router.dart';

/*
RESTFul风格,具有一组相同url前缀的api
 */
abstract class XRESTFulApiRouter {

  //一组相同url前缀, '/system'
  String urlPrefixPath;

  XRESTFulApiRouter({required this.urlPrefixPath});

  Router get router {
    //创建路由
    Router router = Router();
    //手动定义路由
    initRouter(router);

    return router;
  }

  //手动定义路由(适用:当不使用命令自动生成Router时重写)
  void initRouter(Router router){
    /*
  Future<Response> _handler_getSystemDate(Request request) async {
    String response=XResponseUtils.responseBodyJson(code: '200', message: 'ok',data: XDateUtils.getCurrentTime_ms());
    return Response.ok(response,headers: XResponseUtils.responseHeaders());
  }
    //定义路由, 访问:http://192.168.1.254:8080/$prefixUrl/date
    router.post('/date', _handler_getSystemDate);
   */

    // This nested catch-all, will only catch /api/.* when mounted above.
    // Notice that ordering if annotated handlers and mounts is significant.
    //router.all('/<ignored|.*>', (Request request) => Response.notFound(null));

  }

}

